package com.xms.schema.service.relationship;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.xms.core.exception.XmsException;
import com.xms.datacore.service.UpdaterService;
import com.xms.schema.entity.RelationShip;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 * RelationShipUpdaterService
 * </p>
 *
 * @author migo
 * @since 2021/9/8
 */
@CacheConfig(cacheNames = "schema.relationship", keyGenerator = "CacheKeyGenerator")
@Service
public class RelationShipUpdaterService extends UpdaterService<RelationShip> implements IRelationShipUpdaterService {

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(RelationShip entity) throws XmsException, SQLException {
        return super.updateById(entity);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean updateMany(List<RelationShip> entity) throws XmsException, SQLException {
        return super.saveBatch(entity);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(Wrapper<RelationShip> updateWrapper){
        return super.update(updateWrapper);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(RelationShip entity, Wrapper<RelationShip> updateWrapper){
        return super.update(entity, updateWrapper);
    }
}
